import { auth } from "~/auth/server";

const corsHeaders = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
  "Access-Control-Allow-Headers": "Content-Type, Authorization",
  "Access-Control-Allow-Credentials": "true",
};

export function OPTIONS() {
  return new Response(null, { headers: corsHeaders });
}

export async function GET(req: Request) {
  const response = await auth.handler(req);
  for (const key in corsHeaders) {
    response.headers.set(key, corsHeaders[key as keyof typeof corsHeaders]);
  }
  return response;
}

export async function POST(req: Request) {
  const response = await auth.handler(req);
  for (const key in corsHeaders) {
    response.headers.set(key, corsHeaders[key as keyof typeof corsHeaders]);
  }
  return response;
}
